<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2016/1/25
  Time: 12:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更换头像</title>
  <style>
    body {
      font-family: "微软雅黑";
    }
    img{
      border-radius: 10px; width:60px;height:60px;border: 2px solid #fff;
    }
    a{display:inline-block;border-radius: 10px;}
    .bk{ border: 2px solid #74CC00;background-color: #91FF00;}
  </style>
  <link rel='stylesheet' id='custom-layout-css' href='css/bootstrap.min.css' type='text/css' media='all'/>

  <script type='text/javascript' src='../liuyan/js/jquery-1.9.0.min.js'></script>
  <script type="text/javascript" src="../liuyan/layer/layer.js"></script>
</head>
<body style="padding: 25px">
<div id="divHead">
  <% for(int i = 0;i<=48;i++){%>
  <a name="<%=i%>"><img src="images/head/<%=i%>.png"></a>
  <% }%>
</div>
</div>
<div class="modal-footer">
  <button type="button" onclick="closeWindow()" class="btn btn-default" data-dismiss="modal">关闭</button>
  <button type="button" class="btn btn-primary" onclick="saveHead()" data-dismiss="modal">保存头像</button>
</div>
<script type="text/javascript">
  var headId = "";
  $(document).ready(function(){
    $("a").click(function () {
      $("a").removeClass("bk");
      $(this).addClass("bk");
      headId=$(this).attr('name');
    });
  });
  function closeWindow(){
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭
  }
  function saveHead(){
    if(headId==""){
      layer.alert('请选中头像！', {
        icon: 6,
        skin: 'layui-layer-lan' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
      }, function (index) {
        layer.close(index);
      });
    }else{
      var indexLoad = layer.load(0, {shade: false});//加载层
      $.ajax({
        type:"post",
        data:"headId="+headId,
        url:"userLoginController.do?method=alterHead",
        success: function (data) {
          layer.close(indexLoad);//关闭加载层
          if (data == "SUCCESS") {
            //成功后提示删除成功，并且刷新页面
            layer.alert('更换成功^O^', {
              icon: 6,
              skin: 'layui-layer-lan' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
            }, function (index) {
              window.parent.location.reload()
              var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
              parent.layer.close(index); //再执行关闭
            });
          } else {
            layer.alert('更换失败，请重新尝试', {
              icon: 5,
              skin: 'layui-layer-lan' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
            });
          }
        }
      })
    }
  }
</script>
</body>
</html>
